#ifndef RESIZABLEIMAGETEXTEDIT_H
#define RESIZABLEIMAGETEXTEDIT_H

#include <QTextEdit>
#include <QMouseEvent>
#include <QTextFragment>

// 自定义QTextEdit子类以支持图片大小调整
class ResizableImageTextEdit : public QTextEdit
{
    Q_OBJECT

public:
    explicit ResizableImageTextEdit(QWidget *parent = nullptr);

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    bool viewportEvent(QEvent *event) override;

private:
    bool isMouseOnImageCorner(const QPoint &pos);
    
    bool m_resizingImage;
    QPoint m_lastPos;
    int m_currentImagePosition;
    QTextImageFormat m_currentImageFormat;
};

#endif // RESIZABLEIMAGETEXTEDIT_H